package com.kangye.learnstudent.controller;

import com.kangye.learnstudent.entity.*;
import com.kangye.learnstudent.service.InfomationService;
import com.kangye.learnstudent.util.RedisStorageUtil;
import com.kangye.learnstudent.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @program: learndeduo
 * @description: 通知公告请求接口
 * @author: 高天乐
 * @create: 2021-05-17 14:01
 **/
@RestController
@CrossOrigin
@RequestMapping("/infomation")
public class InfomationController {
    //注入service层
    @Autowired
    private InfomationService infomationService;
    @Autowired
    private RedisStorageUtil redisStorageUtil;
    //通知公告
    @RequestMapping("/infomationList")
    public List<Infomation> infomationList(String infomationName,String infomationContent){
        System.out.println("进入controller");
        return infomationService.selinfomation();
    }
    //固定试卷
    @RequestMapping("/FixedTestPaper")
    public List<StudentPaper> FixedTestPaper(String spName){
        System.out.println("FixedTestPaper进入controller");
        return infomationService.selFixedTestPaper();
    }
    //班级试卷
    @RequestMapping("/ClassTestPaper")
    public List<StudentPaper> ClassTestPaper(String classesName){
        System.out.println("ClassTestPaper进入controller");
        return infomationService.selClassTestPaper(classesName);
    }
    //头像
    @RequestMapping("/HeadPortrait")
    public List<User> HeadPortrait(@Param("userUserName") String userUserName){
        System.out.println("HeadPortrait进入controller");

        return infomationService.selHeadPortrait(userUserName);

//        redisUser.getUserUserName()
    }
    //固定试卷的题目
    @RequestMapping("/questionsPaper")
    public List<QuestionBank> questionsPaper(String spName){
        System.out.println("questionsPaper进入controller");
        System.out.println("a="+spName);
        return infomationService.questionsPaper(spName);
    }
    //退出登录
    @RequestMapping("/logout")
    public String logout(HttpSession session) {
        System.out.println("正在退出登录");
        redisStorageUtil.addObjOne("studentUserRedisData","null",1, TimeUnit.SECONDS);
//        System.out.println(200);
        return "200";
    }
}
